Check WPGlobalCart for WordPress MultiSite

Search
TOP

Ignoring Loader Initialization in Headers Synchronization Type

WooCommerce Global Cart - Single Site / Ignoring Loader Initialization in Headers Synchronization Type
Share on FacebookTweet about this on TwitterPin on Pinterest

Ignoring Loader Initialization in Headers Synchronization Type

The WOOGC_LOADER_IGNORE_URI constant allows you to instruct the WooCommerce Global Cart – Single Site plugin to skip its loader initialization for specific incoming requests. This is particularly useful when you are using different APIs and custom calls between the shops and custom data interactions (e.g., AJAX endpoints, tracking scripts, or third-party calls).

 

Definition

Place the following definition in your wp-config.php file, before the line that says /* That’s all, stop editing! Happy blogging. */  and the loader includes:


/**
* Ignore Loader Initialization for Specific URIs
*
* When using Headers Synchronization Type, any request URI matching this
* regex will bypass the WooCommerce Global Cart loader mechanism.
*/
define(
'WOOGC_LOADER_IGNORE_URI',
'\/ts-shipment-tracking\/\?tracking=[\w\d]+'
);


  • Location: wp-config.php (root of your WordPress installation).
  • Scope: Applies globally—across all hooks where the loader initialization occurs.
Purpose
  1. Prevent Unwanted Cart Loads
    Avoid unnecessary session loader initialization on certain endpoints (e.g., tracking widgets, REST API calls).
  2. Eliminate Conflicts
    Stops side effects when third-party scripts or sub-requests manipulate headers without needing a cart context.

Regex Pattern Guidelines
  • Delimiters: Use forward slashes (/). Escape them with backslashes (\/) inside the PHP string.
  • Anchors: Add ^ or $ if you need to match beginning or end of the URI.
  • Quantifiers: Use +, *, or {n,m} for flexible matching (e.g., [\w\d]+).
  • Special Characters: Escape ?, . and other regex metacharacters with a backslash (\?, \.).

Example Patterns

Pattern Matches
^\/api\/cart\/.*$ Any URI starting with /api/cart/
\/ts-shipment-tracking\/\?tracking=[\w\d]+ /ts-shipment-tracking/?tracking=ABC123
`/assets/(css js)/.*.(css

 

 

By defining WOOGC_LOADER_IGNORE_URI appropriately in your wp-config.php, you gain precise control over when the WooCommerce Global Cart loader should be bypassed—streamlining performance, reducing unintended side-effects, and ensuring a smoother user experience.